import 'package:flutter/foundation.dart';
import 'package:get/get.dart';
import 'package:sainbainu/common/values/settings.dart';
import 'package:sign_in_with_apple/sign_in_with_apple.dart';

class AppleService extends GetxService {
  static AppleService get to => Get.find();

  /// apple 授权
  Future<AuthorizationCredentialAppleID> appleAuth() async {
    final credential = await SignInWithApple.getAppleIDCredential(scopes: [
      AppleIDAuthorizationScopes.email,
      AppleIDAuthorizationScopes.fullName,
    ]);
    print({
      // 苹果用户的唯一标识
      'userIdentifier': credential.userIdentifier,
      // jwt加密的idToken,可以在通过接口获取出上面的userIdentifier
      'identityToken': credential.identityToken,
      // 配合secret，keyId，teamId，clientId可以获取到jwt加密的idToken
      'authorizationCode': credential.authorizationCode,
      'givenName': credential.givenName,
      'familyName': credential.familyName,
      'email': credential.email,
      'state': credential.state,
    });
    return credential;
  }
}
